<?php

use console\db\channels\TransferTableMigration;

/**
 * 用户社交关系转移
 * 
 * @author emhome <emhome@163.com>
 * @since 1.0
 */
class m300000_000018_t_user_relation extends TransferTableMigration {

    /**
     * @inheritdoc
     */
    public $sourceDb = 'olddb';

    /**
     * @inheritdoc
     */
    public function validateTransfer(&$data) {
        if (parent::validateTransfer($data)) {
            if ($data['followuid'] < 50) {
                return false;
            }
        }
        return true;
    }

    /**
     * @inheritdoc
     */
    public function getTransferOptions() {
        return [
            'table' => [
                'user_relation' => 'attention',
            ],
            'columns' => [
                'user_id' => 'uid',
                'to_user_id' => 'followuid',
                'remark',
                'created_at' => function($data) {
                    if ($data['inputtime']) {
                        return $data['inputtime'];
                    }
                    return time();
                },
                'updated_at' => function($data) {
                    if ($data['inputtime']) {
                        return $data['inputtime'];
                    }
                    return time();
                },
            ],
        ];
    }

}
